package ssi.actions;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;


import ssi.tools.SendEmail;
import ssi.beans.User;

public class ConfirmDeleteAccountAction extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		request.setCharacterEncoding("UTF-8");
		HttpSession session = request.getSession(true);
		User user=(User)session.getAttribute("user");
		ActionErrors actionErrors = new ActionErrors();
		try{
			
			new SendEmail().sendDeleteEmail(user.getEmail(),user.getPassword());
			actionErrors.add("info",
					new ActionMessage("error.deleteAccountInfo"));
			
			
		}catch(Exception e){
			actionErrors.add("info",
					new ActionMessage("error.catch"));
			
		}
		if(actionErrors.size() !=0){
			extracted(request, actionErrors);
			return new ActionForward(mapping.getInput());
		}
		
		return null;
	}
	private void extracted(HttpServletRequest request, ActionErrors actionErrors) {
		saveErrors(request, actionErrors);
	}
	
}
